﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ecdl.demo.model.expression {
    public class Or : CompositeExpression {
        public Or() {
        }

        public override ExpressionState Evaluate(ExpressionContext context) {
            bool result = false;
            IEnumerator<Expression> expressionEnumerator = Expressions.AsEnumerable<Expression>().GetEnumerator();
            MultiExpressionState expressionState = new MultiExpressionState(this);

            while (expressionEnumerator.MoveNext()) {
                ExpressionState childState = expressionEnumerator.Current.Evaluate(context);
                expressionState.ChildExpressions.Add(childState);
                result |= childState.IsOk;
            }
            expressionState.IsOk = result;
            return expressionState;
        }

    }

    public class OrDTO : MultiExpressionDTO {
        public OrDTO() : base(typeof(Or)){    
        }
    }
}
